<%@page import="com.ssm.util.BusinessException"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isErrorPage="true" %>
<%@page isErrorPage="true"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ page import="java.io.*"%>
<%
    response.setStatus(HttpServletResponse.SC_OK);
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
        + path + "/";
%>
  <%--   <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%> --%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
		<meta charset="UTF-8">
		<title>错误页面展示</title>
		<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
		<link rel="stylesheet" type="text/css" href="<%=basePath %>css/error_page.css"/>
	</head>
<script type="text/javascript"
	src="<%=basePath%>js/3rd/jquery-3.1.1.min.js"></script>
<script>
            function showErrorMessage(){
                $("#errorMessageDiv").slideToggle();
            }
            $(document).ready(showErrorMessage);
        </script>
	<body>
		<div class="wrap">
			<img class="icon_sorry" src="<%=basePath %>img/error/error.png"/>
			<div class="error_area">
				<p class="error_text1">抱歉，您想要查找的页面有误或是不存在哦 ~</p>
				<p class="error_text2">请检查地址栏中的输入是否错误或者是它有可能已经过期啦</p>
				<a id="showErrorMessageButton" href="javascript:showErrorMessage();" class="error_info">查看详细错误信息</a>
				<div id="errorMessageDiv">
				<pre>
                <%
                    try {
                        //全部内容先写到内存，然后分别从两个输出流再输出到页面和文件
                        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                        PrintStream printStream = new PrintStream(byteArrayOutputStream);

                        printStream.println();
                        printStream.println("用户信息");
                        printStream.println("账号：" + request.getSession().getAttribute("userName"));
                        printStream.println("访问的路径: " + request.getAttribute("javax.servlet.forward.request_uri"));
                        printStream.println();

                        printStream.println("异常信息");
                        exception = (BusinessException)request.getAttribute("exception");
                        printStream.println(exception.getClass() + " : " + exception.getMessage());
                        printStream.println();

                        Enumeration<String> e = request.getParameterNames();
                        if (e.hasMoreElements()) {
                            printStream.println("请求中的Parameter包括：");
                            while (e.hasMoreElements()) {
                                String key = e.nextElement();
                                printStream.println(key + "=" + request.getParameter(key));
                            }
                            printStream.println();
                        }

                        /* printStream.println("堆栈信息");
                        exception.printStackTrace(printStream);
                        printStream.println(); */

                        out.print(byteArrayOutputStream);    //输出到网页

                        File dir = new File(request.getRealPath("/errorLog"));
                        if (!dir.exists()) {
                            dir.mkdir();
                        }
                        String timeStamp = new SimpleDateFormat("yyyyMMddhhmmssS").format(new Date());
                        FileOutputStream fileOutputStream = new FileOutputStream(new File(dir.getAbsolutePath() + File.separatorChar + "error-" + timeStamp + ".txt"));
                        new PrintStream(fileOutputStream).print(byteArrayOutputStream); //写到文件
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                %>
            </pre>
			</div>
				<!-- 返回按钮 -->
				<!-- <div class="back_btn">
					<a href="welcome.html" target="welcomeFrame">返回首页</a>
					<a>返回上一页</a>
				</div> -->
			</div>
			<!-- 版尾  -->
			<div class="ending">
				Copyright© 2017-2018 西安磐基新能源科技有限公司
			</div>
		</div>
	</body>
	<script src="<%=basePath%>js/3rd/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		var h = document.documentElement.clientHeight;
		$(".wrap").css("height", h);
		
		
		$(".error_info").click(function(){
			$(".error_explain").slideToggle();
		});
	</script>
</html>